home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Games Collection 1
/
software vault.zip
/
software vault
/
CDR10
/
MAPEDIT.ZIP
/
SAMPGAME
/
PCX.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-04-11
|
30KB
|
855 lines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <dos.h>
#include <malloc.h>
#include <graph.h>
#define FALSE 0
#define TRUE 1
#define PCX_HERC 0xff /* Hercules 720 x 348 monochrome mode */
#define PCX_COMP_FLAG 0xc0 /* Compressed data flag mask */
#define PCX_COMP_MASK 0x3f /* Data repeat count mask */
#define PCX_PAL_MASK 0x03 /* Palette interpretation mask */
#define PCX_EPAL_FLAG 0x0c /* Extended palette flag */
#define PCX_PAL_SIZE 16 /* File header palette size */
#define PCX_EPAL_SIZE 256 /* Extended palette size */
#define PCX_CGA_BKGND(x) (x[0].red >> 4) /* Background color */
#define PCX_CGA_BURST(x) (x[1].red & 0x80) /* Color burst */
#define PCX_CGA_SELECT(x) (x[1].red & 0x40) /* Palette selector */
#define PCX_CGA_INTENSITY(x) (x[1].red & 0x20) /* Intensity */
#define PCX_MAXLINESZ 640 /* Maximum PCX line buffer size */
typedef int BOOL; /* Boolean flag */
typedef unsigned char BYTE; /* 8-bit data type */
typedef unsigned int WORD; /* 16-bit data type */
typedef struct pcx_pal /* PCX palette array element */
{
BYTE red; /* Red intensity */
BYTE green; /* Green intensity */
BYTE blue; /* Blue intensity */
}PCX_PAL;
struct mypal_struct{
int r;
int g;
int b;
}mypal[256];
typedef struct pcx_hdr /* PCX file header (Version 5) */
{
BYTE pcx_id; /* Always 0x0a for PCX files */
BYTE version; /* Version number */
BYTE encoding; /* 1 = PCX run length encoding */
BYTE bppixel; /* Number of bits/pixel per color plane */
WORD xul; /* X-position of upper left corner */
WORD yul; /* Y-position of upper left corner */
WORD xlr; /* X-position of lower right corner */
WORD ylr; /* Y-position of lower right corner */
WORD horz_res; /* Horizontal resolution */
WORD vert_res; /* Vertical resolution */
PCX_PAL palette[PCX_PAL_SIZE]; /* Hardware R-G-B palette */
BYTE reserved; /* Unused in Version 5 */
BYTE nplanes; /* Number of color planes */
WORD bppscan; /* Number of bytes per plane scan line */
WORD palette_type; /* Palette interpretation */
WORD scrn_width; /* Horizontal screen size in pixels */
WORD scrn_height; /* Vertical screen size in pixels */
BYTE filler[54]; /* Padding to fill out 128-byte header */
}PCX_HDR;
typedef struct pcx_workblk /* PCX image file workblock */
{
/* File header */
FILE *fp; /* PCX image file pointer */
PCX_HDR header; /* PCX image file header */
PCX_PAL *palettep; /* Color palette pointer */
BOOL epal_flag; /* Extended color palette flag */
/* Image manipulation variables */
int num_bytes; /* Number of bytes to display */
int mask; /* Unseen pixels mask */
unsigned long page_offset; /* Display page address offset */
/* Image manipulation function pointer */
void (*pcx_funcp)(struct pcx_workblk *, unsigned char _far *, int);
} PCX_WORKBLK;
typedef struct pcx_vsb /* BIOS video services data save buffer */
{
struct pcx_ppt /* Primary Pointer Table */
{
void _far *vptp; /* Video Parameter Table pointer */
unsigned char _far *dsap; /* Dynamic Save Area pointer */
void _far *tmacgp; /* Text Mode Aux Char Generator pointer */
void _far *gmacgp; /* Graphics Mode Aux Char Generator ptr */
void _far *sptp; /* Secondary Pointer Table pointer */
void _far *rsv_1; /* Reserved */
void _far *rsv_2; /* Reserved */
} pcx_ppt;
struct pcx_ppt _far *prev_pptp;
}PCX_VSB;
static BOOL pcx_encode(int, int, FILE *);
static BOOL pcx_init_palette(PCX_PAL *, int);
static BOOL pcx_write_extpal(FILE *);
static BOOL pcx_write_line(unsigned char *, int, FILE *);
static BOOL pcx_write_init(PCX_WORKBLK *, int, int, int, int);
static void pcx_get_cga(PCX_WORKBLK *, unsigned char _far *, int);
static void pcx_get_ega(PCX_WORKBLK *, unsigned char _far *, int);
static void pcx_get_herc(PCX_WORKBLK *, unsigned char _far *, int);
static void pcx_get_vga(PCX_WORKBLK *, unsigned char _far *, int);
static BOOL pcx_read_init(PCX_WORKBLK *, int, int);
static BOOL pcx_read_extpal(PCX_WORKBLK *);
static BOOL pcx_read_header(PCX_WORKBLK *);
static BOOL pcx_read_line(PCX_WORKBLK *, unsigned char *, int);
static BOOL pcx_set_palette(PCX_PAL *, int);
static void pcx_put_vga(PCX_WORKBLK *, unsigned char _far *, int);
BOOL pcx_close(PCX_WORKBLK *);
BOOL load_pcx(char *, char far *);
PCX_WORKBLK *pcx_open(char *, BOOL);
BOOL pcx_init_dsa(PCX_VSB **);
BOOL pcx_isvga(void);
BOOL save_pcx(char *,char far *);
void pcx_free_dsa(PCX_VSB *);
char far *buf;
char far *write_buf;
static BYTE pcx_EGA_DefPal_1[16] = /* Modes 0x0d and 0x0e */
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x12, 0x13,
0x14, 0x15, 0x16, 0x17
};
static BYTE pcx_EGA_DefPal_2[16] = /* Mode 0x0f */
{
0x00, 0x08, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00,
0x00, 0x18, 0x00, 0x00
};
static BYTE pcx_EGA_DefPal_3[16] = /* Mode 0x10 */
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39, 0x3a, 0x3b,
0x3c, 0x3d, 0x3e, 0x3f
};
BOOL load_pcx(char *fname, char far *buffer)
{
int bpline; /* Number of bytes per scan line */
int line_num; /* Scan line number */
int max_lines; /* Maximum number of scan lines */
unsigned char *linep; /* PCX scan line buffer pointer */
BOOL status = TRUE; /* Return status */
PCX_WORKBLK *wbp; /* PCX image file workblock pointer */
int vmode=0x13,page=0;
buf=buffer;
/* Open a PCX image file workblock */
if ((wbp = pcx_open(fname, FALSE)) == (PCX_WORKBLK *) NULL)
return (FALSE);
/* Initialize the workblock for reading */
if (pcx_read_init(wbp, vmode, page) == FALSE)
{
(void) pcx_close(wbp); /* Close the PCX workblock */
return (FALSE);
}
/* Calculate the image height */
max_lines = wbp->header.yul + wbp->header.ylr + 1;
/* Calculate number of bytes per line (for all color planes) */
bpline = wbp->header.bppscan * wbp->header.nplanes;
/* Allocate the PCX scan line buffer */
if ((linep = (unsigned char *) malloc(bpline)) != (unsigned char *)NULL)
{
/* Set the file pointer to the beginning of the encoded image data */
if (fseek(wbp->fp, (long) (sizeof(PCX_HDR)), SEEK_SET) != 0)
status = FALSE;
if (pcx_set_palette(wbp->palettep, vmode) == FALSE)
status = FALSE;
/* Read the image line by line */
for (line_num = 0; line_num < max_lines; line_num++)
{
/* Read the current scan line */
if ((status = pcx_read_line(wbp, linep, bpline)) == FALSE)
{
status = FALSE;
break;
}
/* Display the current scan line */
wbp->pcx_funcp(wbp, (unsigned char _far *) linep, line_num);
free(linep); /* Free the PCX scan line buffer */
}
}
else
status = FALSE;
if (pcx_close(wbp) == FALSE) /* Close the PCX workblock */
status = FALSE;
return (status);
}
static BOOL pcx_read_init(PCX_WORKBLK *wbp,int vmode,int page)
{
int width; /* Display width */
int leftover; /* Number of unseen bits */
BOOL status = TRUE; /* Return status */
/* Read the file header */
if ((pcx_read_header(wbp)) == FALSE)
return (FALSE);
/* Initialize the workblock color palette pointer */
wbp->palettep = wbp->header.palette;
wbp->epal_flag = FALSE;
/* Read the extended palette (if any) */
if (pcx_read_extpal(wbp) == FALSE)
return (FALSE);
/* Initialize the display page address offset */
wbp->page_offset = (unsigned long) 0L;
/* Calculate number of bytes to display */
wbp->num_bytes = min((wbp->header.xlr - wbp->header.xul + 1), 320);
wbp->mask = 0; /* Dummy parameter */
wbp->pcx_funcp = pcx_put_vga; /* Set the display function ptr */
return (status);
}
static BOOL pcx_read_header(PCX_WORKBLK *wbp)
{
BOOL status = TRUE; /* Status flag */
PCX_HDR *hdrp; /* PCX file header buffer pointer */
hdrp = &(wbp->header); /* Initialize the file header pointer */
/* Read the file header */
if (fseek(wbp->fp, 0L, SEEK_SET) != 0)
status = FALSE;
if (fread(hdrp, sizeof(PCX_HDR), 1, wbp->fp) != 1)
status = FALSE;
/* Validate the PCX file format */
if ((hdrp->pcx_id != 0x0a) || (hdrp->encoding != 1))
status = FALSE;
return (status);
}
static BOOL pcx_read_extpal( PCX_WORKBLK *wbp )
{
int indicator; /* PCX extended palette indicator */
/* Position the file pointer to the extended palette indicator byte */
if (fseek(wbp->fp, -769L, SEEK_END) != 0)
return (FALSE);
/* Read the (assumed) extended palette indicator byte */
if ((indicator = getc(wbp->fp)) == EOF)
return (FALSE);
if (indicator == PCX_EPAL_FLAG) /* Check for indicator byte */
{
/* Allocate an extended palette buffer */
if ((wbp->palettep = (PCX_PAL *) calloc(sizeof(PCX_PAL),
PCX_EPAL_SIZE)) == (PCX_PAL *) NULL)
return (FALSE);
/* Read the extended palette */
if (fread(wbp->palettep, sizeof(PCX_PAL), PCX_EPAL_SIZE, wbp->fp) !=
PCX_EPAL_SIZE)
{
free(wbp->palettep); /* Free the extended palette buffer */
return (FALSE);
}
wbp->epal_flag = TRUE; /* Indicate extended palette present */
}
return (TRUE);
}
static BOOL pcx_read_line(PCX_WORKBLK *wbp,unsigned char *linep,int bpline)
{
int data; /* Image data byte */
int count; /* Image data byte repeat count */
int offset = 0; /* Scan line buffer offset */
while (offset < bpline) /* Decode current scan line */
{
if ((data = getc(wbp->fp)) == EOF) /* Get next byte */
return (FALSE);
/* If top two bits of byte are set, lower six bits show how */
/* many times to duplicate next byte */
if ((data & PCX_COMP_FLAG) == PCX_COMP_FLAG)
{
count = data & PCX_COMP_MASK; /* Mask off repeat count */
if ((data = getc(wbp->fp)) == EOF) /* Get next byte */
return (FALSE);
memset(linep, data, count); /* Duplicate byte */
linep += count;
offset += count;
}
else
{
*linep++ = (unsigned char) data; /* Copy byte */
offset++;
}
}
return (TRUE);
}
static BOOL pcx_set_palette(PCX_PAL *palettep,int vmode)
{
int i; /* Scratch counter */
for (i = 0; i < PCX_EPAL_SIZE; i++)
pcx_setDAC(i,palettep[i].red >> 2,palettep[i].green>>2,palettep[i].blue>>2);
return (TRUE);
}
pcx_setDAC(int n,int r,int g,int b)
{
outp(0x3c8,n);
outp(0x3c9,r);
outp(0x3c9,g);
outp(0x3c9,b);
mypal[n].r=r;
mypal[n].g=g;
mypal[n].b=b;
}
static void pcx_put_vga(PCX_WORKBLK *wbp,unsigned char _far *linep,int line_num)
{
unsigned char _far *displayp; /* Display buffer pointer */
/* Calculate buffer pointer */
displayp = (unsigned char _far *)buf + line_num * 320;
/* Copy data from the scan line buffer to the VGA display buffer */
(void) _fmemcpy(displayp, linep, wbp->num_bytes);
}
PCX_WORKBLK *pcx_open
(
char *fname,
BOOL wrt_flag
)
{
PCX_WORKBLK *wbp; /* PCX image file workblock pointer */
/* Allocate a workblock */
if ((wbp = (PCX_WORKBLK *) malloc(sizeof(PCX_WORKBLK))) == NULL)
return (NULL);
/* Open the PCX image file in binary mode */
if (wrt_flag == FALSE)
wbp->fp = fopen(fname, "rb"); /* Open for reading */
else
wbp->fp = fopen(fname, "wb"); /* Open for writing */
if (wbp->fp == NULL) /* Check for successful file opening */
{
free(wbp); /* Free the workblock memory */
return (NULL);
}
return (wbp); /* Return the workblock pointer */
}
BOOL pcx_close
(
PCX_WORKBLK *wbp
)
{
free(wbp->palettep); /* Free the extended palette (if it exists) */
free(wbp); /* Free the PCX image file workblock */
if (fclose(wbp->fp) == EOF) /* Close the PCX image file */
return (FALSE);
return (TRUE);
}
BOOL pcx_isvga(void)
{
unsigned char *vinfop; /* VGA information buffer pointer */
union REGS regs; /* 80x86 register values */
struct SREGS sregs; /* 80x86 segment register values */
/* Allocate a VGA functionality/state information buffer */
if ((vinfop = (unsigned char *) malloc(sizeof(unsigned char) * 64)) ==
NULL)
return (FALSE);
/* Attempt to read the VGA information */
regs.h.ah = 0x1b; /* Select "Return VGA Info" BIOS routine */
regs.x.bx = 0; /* Implementation type */
/* Get the VGA information buffer offset value */
regs.x.di = (unsigned int) vinfop;
segread(&sregs); /* Get the current DS segment register value */
sregs.es = sregs.ds;
int86x(0x10, ®s, ®s, &sregs); /* Call BIOS video service */
free(vinfop); /* Free the VGA information buffer */
/* The value 0x1b is returned in register AL only if a VGA display */
/* adapter is present */
if (regs.h.al == 0x1b)
return (TRUE);
else
return (FALSE);
}
BOOL save_pcx
(
char *fname,
char far * buffer,
)
{
int bpline; /* Number of bytes per scan line */
int line_num; /* Scan line number */
unsigned char *linep; /* Image scan line buffer pointer */
BOOL status = TRUE; /* Return status */
PCX_WORKBLK *wbp; /* PCX image file workblock pointer */
int width=320;
int height=200;
int vmode=0x13;
int page=0;
write_buf=buffer;
/* Open a PCX image file workblock */
if ((wbp = pcx_open(fname, TRUE)) == (PCX_WORKBLK *) NULL)
return (FALSE);
/* Initialize the workblock for writing */
if (pcx_write_init(wbp, vmode, page, width, height) == FALSE)
status = FALSE;
/* Calculate number of bytes per line (for all color planes) */
bpline = wbp->header.bppscan * wbp->header.nplanes;
/* Allocate a scan line buffer */
if (status == TRUE)
if ((linep = (unsigned char *) malloc(bpline)) == (unsigned char *)
NULL)
status = FALSE;
/* Write the file header to the file */
if (status == TRUE)
if (fwrite(&(wbp->header), sizeof(PCX_HDR), 1, wbp->fp) != 1)
status = FALSE;
/* Write the encoded image data to the file */
if (status == TRUE)
{
for (line_num = 0; line_num <= (int) wbp->header.ylr; line_num++)
{
/* Get the current video buffer scan line */
wbp->pcx_funcp(wbp, (unsigned char _far *) linep, line_num);
/* Encode the scan line and write it to the file */
if (pcx_write_line(linep, bpline, wbp->fp) == FALSE)
{
status = FALSE;
break;
}
}
}
if (status == TRUE)
if (pcx_write_extpal(wbp->fp) == FALSE)
status = FALSE;
if (pcx_close(wbp) == FALSE) /* Close the PCX workblock */
status = FALSE;
free(linep); /* Free the scan line buffer */
/* Remove the PCX image file if an error occurred */
if (status == FALSE)
(void) remove(fname);
return (status);
}
BOOL pcx_init_dsa
(
PCX_VSB **vsbpp
)
{
unsigned char _far *dsap; /* Dynamic Save Area pointer */
PCX_VSB *vsbp; /* Video services data save buffer ptr */
*vsbpp = (PCX_VSB *) NULL; /* Initialize returned pointer */
/* Allocate a Dynamic Save Area buffer */
if ((dsap = (unsigned char _far *) _fmalloc(sizeof(unsigned char) *
256)) == (unsigned char _far *) NULL)
return (FALSE);
/* Allocate a BIOS video services data save buffer */
if ((vsbp = (PCX_VSB *) malloc(sizeof(PCX_VSB))) == (PCX_VSB *) NULL)
{
_ffree(dsap); /* Free the Dynamic Save Area buffer */
return (FALSE);
}
/* Save the existing Primary Pointer Table pointer */
vsbp->prev_pptp = *((struct pcx_ppt _far * _far *) 0x004000a8L);
/* Copy the existing Primary Pointer Table into the buffer */
(void) _fmemcpy((struct pcx_ppt _far *) &(vsbp->pcx_ppt),
vsbp->prev_pptp, sizeof(struct pcx_ppt));
vsbp->pcx_ppt.dsap = dsap; /* Update the Dynamic Save Area ptr */
/* Update the Primary Pointer Table pointer in the Video Save Table */
*((struct pcx_ppt _far * _far *) 0x004000a8L) = &(vsbp->pcx_ppt);
*vsbpp = vsbp; /* Return Video Services data save buffer ptr */
return (TRUE);
}
void pcx_free_dsa
(
PCX_VSB *vsbp
)
{
/* Restore the previous primary pointer table pointer */
*((struct pcx_ppt _far * _far *) 0x004000a8L) = vsbp->prev_pptp;
_ffree(vsbp->pcx_ppt.dsap); /* Free the Dynamic Save Area */
free(vsbp); /* Free the Video Services data save buffer */
}
static BOOL pcx_write_init
(
PCX_WORKBLK *wbp,
int vmode,
int page,
int width,
int height
)
{
int max_width; /* Maximum image width */
int max_height; /* Maximum image height */
int shift; /* Mask shift value */
BOOL status = TRUE; /* Return status */
PCX_HDR *hdrp; /* File header buffer pointer */
/* Initialize the display page address offset */
wbp->page_offset = (unsigned long) 0L;
hdrp = &(wbp->header); /* Initialize the file header pointer */
/* Initialize the header constants */
hdrp->pcx_id = 0x0a; /* PCX format identifier */
hdrp->version = 5; /* Version number */
hdrp->encoding = 1; /* Encoding format (run-length) */
hdrp->xul = 0; /* Upper left x-position */
hdrp->yul = 0; /* Upper left y-position */
hdrp->reserved = 0; /* (Used to be video mode) */
hdrp->palette_type = 1; /* Color or b&w palette type */
memset(hdrp->filler, 0, sizeof(hdrp->filler)); /* Padding */
/* Initialize the video mode-dependent parameters */
max_width = min(width, 320); /* Maximum image width */
max_height = min(height, 200); /* Maximum image height */
hdrp->bppixel = 8; /* Bits per pixel */
hdrp->horz_res = 320; /* Horizontal resolution */
hdrp->vert_res = 200; /* Vertical resolution */
hdrp->nplanes = 1; /* Number of color planes */
/* Calculate number of bytes to copy */
wbp->num_bytes = max_width;
shift = 0; /* Dummy parameter */
wbp->pcx_funcp = pcx_get_vga; /* Set display capture fcn ptr */
/* Initialize common video mode-dependent parameters */
hdrp->xlr = max_width - 1; /* Lower right x-position */
hdrp->ylr = max_height - 1; /* Lower right y-position */
hdrp->scrn_width = hdrp->horz_res; /* Screen width */
hdrp->scrn_height = hdrp->vert_res; /* Screen height */
/* Calculate mask for "white" data */
if (shift != 0)
wbp->mask = 0xff >> shift;
else
wbp->mask = 0x00;
/* Initialize the file header palette */
status = pcx_init_palette(hdrp->palette, vmode);
/* Calculate number of bytes per color plane scan line (must be an */
/* even number of bytes) */
hdrp->bppscan = 2 * (((((hdrp->xlr * hdrp->bppixel) + 7) / 8) + 1) / 2);
return (status);
}
static BOOL pcx_init_palette
(
PCX_PAL *palettep,
int vmode
)
{
int i; /* Scratch counter */
int val; /* Current palette register value */
int red; /* Temporary value */
int green; /* Temporary value */
int blue; /* Temporary value */
unsigned char *ega_palp; /* EGA/VGA palette buffer pointer */
unsigned char _far *dsap; /* Dynamic Save Area pointer */
union REGS regs; /* 80x86 register values */
struct SREGS sregs; /* 80x86 segment register values */
memset(palettep, 0, sizeof(PCX_PAL) * PCX_PAL_SIZE);
return (TRUE);
}
static BOOL pcx_write_line
(
unsigned char *linep,
int buflen,
FILE *fp
)
{
int curr_data; /* Current data byte */
int prev_data; /* Previous data byte */
int data_count; /* Data repeat count */
int line_count; /* Scan line byte count */
prev_data = *linep++; /* Initialize the previous data byte */
data_count = 1;
line_count = 1;
while (line_count < buflen) /* Encode scan line */
{
curr_data = *linep++; /* Get the current data byte */
line_count++; /* Increment the scan line counter */
if (curr_data == prev_data) /* Repeating data bytes ? */
{
data_count++; /* Increment the data repeat count */
/* Check for maximum allowable repeat count */
if (data_count == PCX_COMP_MASK)
{
/* Encode the data */
if (pcx_encode(prev_data, data_count, fp) == FALSE)
return (FALSE);
data_count = 0; /* Reset the data repeat count */
}
}
else /* End of repeating data bytes */
{
if (data_count > 0)
{
/* Encode the data */
if (pcx_encode(prev_data, data_count, fp) == FALSE)
return (FALSE);
}
prev_data = curr_data; /* Current data byte now previous */
data_count = 1;
}
}
if (data_count > 0) /* Any remaining data ? */
{
/* Encode the data */
if (pcx_encode(prev_data, data_count, fp) == FALSE)
return (FALSE);
}
return (TRUE);
}
static BOOL pcx_encode
(
int data,
int count,
FILE *fp
)
{
if (((data & PCX_COMP_FLAG) == PCX_COMP_FLAG) || count > 1)
{
/* Write the count byte */
if (putc(PCX_COMP_FLAG | count, fp) == EOF)
return (FALSE);
}
/* Write the data byte */
if (putc(data, fp) == EOF)
return (FALSE);
return (TRUE);
}
static BOOL pcx_write_extpal
(
FILE *fp
)
{
int i; /* Scratch counter */
BOOL status = TRUE; /* Return status */
PCX_PAL *palettep; /* Extended PCX palette buffer pointer */
unsigned char *vga_palp; /* 256-color VGA palette buffer pointer */
union REGS regs; /* 80x86 register values */
struct SREGS sregs; /* 80x86 segment register values */
/* Allocate an extended PCX palette buffer */
if ((palettep = (PCX_PAL *) calloc(sizeof(PCX_PAL), PCX_EPAL_SIZE)) ==
(PCX_PAL *) NULL)
return (FALSE);
/* Allocate a 256-color VGA palette buffer */
if ((vga_palp = (unsigned char *) calloc(sizeof(unsigned char), 768))
== (unsigned char *) NULL)
{
free(palettep); /* Free the extended PCX palette buffer */
return (FALSE);
}
for (i = 0; i < PCX_EPAL_SIZE; i++)
{
palettep[i].red = mypal[i].r<<2;
palettep[i].green = mypal[i].g<<2;
palettep[i].blue = mypal[i].b<<2;
}
/* Write the extended PCX palette indicator byte to the file */
if (status == TRUE)
if (fputc(PCX_EPAL_FLAG, fp) == EOF)
status = FALSE;
/* Write the extended PCX palette to the file */
if (status == TRUE)
if (fwrite(palettep, sizeof(PCX_PAL), PCX_EPAL_SIZE, fp) !=
PCX_EPAL_SIZE)
status = FALSE;
free(palettep); /* Free the extended PCX palette buffer */
free(vga_palp); /* Free the VGA palette buffer */
return (status);
}
static void pcx_get_vga
(
PCX_WORKBLK *wbp,
unsigned char _far *linep,
int line_num
)
{
unsigned char _far *displayp; /* Display buffer pointer */
/* Calculate buffer pointer */
displayp = (unsigned char _far *) write_buf + line_num * 320;
/* Copy data from the VGA display buffer to the scan line buffer */
(void) _fmemcpy(linep, displayp, wbp->num_bytes);
/* Pad scan line with "white" data byte (if necessary) */
if (wbp->num_bytes & 1)
linep[wbp->num_bytes] = 0xff;
}